package com.yvdelx.cyclowomen.object;

import com.yvdelx.cyclowomen.utility.DateUtility;
import com.yvdelx.cyclowomen.utility.LogUtility;

import org.simpleframework.xml.Element;

import java.util.Date;

import static com.yvdelx.cyclowomen.utility.StringUtility.CST_XML_DATA_COMMENT_ELEMENT;
import static com.yvdelx.cyclowomen.utility.StringUtility.CST_XML_DATA_DATE_ELEMENT;
import static com.yvdelx.cyclowomen.utility.StringUtility.CST_XML_DATA_DAY_ELEMENT;
import static com.yvdelx.cyclowomen.utility.StringUtility.CST_XML_DATA_NOMINAL_CONDITION_ELEMENT;
import static com.yvdelx.cyclowomen.utility.StringUtility.CST_XML_DATA_QUANTITY_ELEMENT;
import static com.yvdelx.cyclowomen.utility.StringUtility.CST_XML_DATA_SENSATION_ELEMENT;
import static com.yvdelx.cyclowomen.utility.StringUtility.CST_XML_DATA_TEMPERATURE_ELEMENT;

/**
 * Object class Day
 * Created by ydelvaux on 22/02/14.
 */
@Element(name=CST_XML_DATA_DAY_ELEMENT)
public class Day implements Comparable<Day> {

    @Element(name=CST_XML_DATA_DATE_ELEMENT, type=Date.class)
    private Date date;

    @Element(name=CST_XML_DATA_TEMPERATURE_ELEMENT, type = Float.class, required = false)
    private Float temperature;

    @Element(name=CST_XML_DATA_NOMINAL_CONDITION_ELEMENT, type = Boolean.class, required = false)
    private Boolean isNominalCondition;

    @Element(name=CST_XML_DATA_SENSATION_ELEMENT, type = EnumSensation.class, required = false)
    private EnumSensation sensation;

    @Element(name=CST_XML_DATA_QUANTITY_ELEMENT, type = Float.class, required = false)
    private Float quantity;

    private EnumNature nature;

    @Element(name=CST_XML_DATA_COMMENT_ELEMENT, type = String.class, required = false)
    private String comment;

    public Day() {
        super();
    }

    /**
     * Day Object Constructor
     *
     * @param date Date
     * @param temperature Float
     * @param sensation EnumSensation
     * @param comment String
     */
    public Day(Date date, Float temperature, EnumSensation sensation, String comment, float quantity,
               boolean isNominalCondition) {
        this.date = date;
        this.temperature = temperature;
        this.sensation = sensation;
        this.comment = comment;
        this.quantity = quantity;
        this.isNominalCondition = isNominalCondition;
    }

    @SuppressWarnings("unused")
    public Float getQuantity() {
        return this.quantity;
    }

    @SuppressWarnings("unused")
    public void setQuantity(Float quantity) {
        this.quantity = quantity;
    }

    public Date getDate() {
        return this.date;
    }

    public Float getTemperature() {
        return this.temperature;
    }

    public EnumSensation getSensation() {
        return this.sensation;
    }

    public EnumNature getNature() {
        return this.nature;
    }

    public String getComment() {
        return this.comment;
    }

    public void setDate(Date date) {
        this.date = date;
    }

    @SuppressWarnings("all")
    public void setTemperature(Float temperature) {
        this.temperature = temperature;
    }

    @SuppressWarnings("unused") // use by XML factory
    public void setSensation(EnumSensation sensation) {
        this.sensation = sensation;
    }

    public void setNature(EnumNature nature) {
        this.nature = nature;
    }

    @SuppressWarnings("all") // use by XML factory
    public void setComment(String comment) {
        this.comment = comment;
    }

    @SuppressWarnings("unused")
    public Boolean getIsNominalCondition() {
        if(this.isNominalCondition == null){
            this.isNominalCondition = Boolean.TRUE;
        }
        return this.isNominalCondition;
    }

    @SuppressWarnings("unused")
    public void setIsNominalCondition(Boolean isNominalCondition) {
        this.isNominalCondition = isNominalCondition;
    }

    @Override
    public String toString(){
        if(LogUtility.isDebug()){
            return "Day ["
                    + "Date : " + DateUtility.dateToString(getDate()) + ", "
                    + "Sensation : " + getSensation().toString() + ", "
                    + "Comment : " + getComment()
                    + "]";
        }
        return DateUtility.dateToString(this.getDate());
    }

    /**
     *
     * @param day Day
     * @return Integer
     */
    @Override @SuppressWarnings("all")
    public int compareTo(Day day){
        return this.date.compareTo(day.getDate());
    }
}
